package com.viettel.pon.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.viettel.pon.R;
import com.viettel.pon.form.InfomationForm;

public class ListPolesAdapter  extends ArrayAdapter<InfomationForm>{
	
	private final Context _context;
	private final ArrayList<InfomationForm> values;
	InfomationForm item=null;
	private final int widthScreen;
	
	public ListPolesAdapter(Context _context, ArrayList<InfomationForm> values,int widthScreen) {
		super(_context, R.layout.item_poles, values);
		// TODO Auto-generated constructor stublist_item_view
		this._context = _context;
		this.values = values;
		this.widthScreen=widthScreen;
	}

	@Override
	public View getView(final int position, View convertView,
			ViewGroup parent) {
		// TODO Auto-generated method stub
		// make sure we have a view work with
		final ViewHolder holder;
		item=new InfomationForm();
		item=getItem(position);
		
			LayoutInflater inflater = (LayoutInflater) _context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
			convertView = inflater.inflate( R.layout.item_poles, null );
			holder = new ViewHolder();
			holder.colCode = (TextView) convertView.findViewById(R.id.txtColCode);
			holder.colType = (TextView) convertView.findViewById(R.id.txtColType);
			holder.colPosition = (TextView) convertView.findViewById(R.id.txtPosition);
			
		// fill the view
		if(item.getCol_type()==1){
			holder.colType.setText("Loại cột: Vuông đơn");
		}
		if(item.getCol_type()==2){
			holder.colType.setText("Loại cột: Vuông đôi");
		}
		if(item.getCol_type()==3){
			holder.colType.setText("Loại cột: Tròn đơn");
		}
		if(item.getCol_type()==4){
			holder.colType.setText("Loại cột: Tròn đôi");
		}
		if(item.getCol_type()==5){
			holder.colType.setText("Loại cột: Cột thép");
		}
		if(item.getCol_type()==6){
			holder.colType.setText("Loại cột: Cột gỗ");
		}
		if(item.getOwner()==1){
			holder.colCode.setText("Cột: "+item.getCol_code()+"_Viettel");
		}
		if(item.getOwner()==2){
			holder.colCode.setText("Cột: "+item.getCol_code()+"_VNPT");
		}
		if(item.getOwner()==3){
			holder.colCode.setText("Cột: "+item.getCol_code()+"_Điện lực");
		}
		if(item.getOwner()==4){
			holder.colCode.setText("Cột: "+item.getCol_code()+"_Xã");
		}
		holder.colPosition.setText("("+item.getLatitude()+" , "+item.getLongtitude()+")");

		return convertView;
	}

	public class ViewHolder {
		TextView colCode;
		TextView colType;
		TextView colPosition;
	}

}
